Page({
    data: {
        array: ['无锡', '锡山', '惠山', '滨湖', '梁溪', '新吴', '江阴', '宜兴'],
        index: 0,//默认显示位置
        currentIndex: 0,
        show: true
    },
    bindPickerChange: function (e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            index: e.detail.value
        });
        this.onLoad();
    },
    search() {
        swan.navigateTo({
            url: '../search/search'
        });
    },
    // 更多
    getMoreGoods(e) {
        let id = e.currentTarget.dataset.id;
        swan.navigateTo({
            url: '../product/product?id=' + id
        });
    },
    // 详情
    getGoodDetail(e) {
        var that = this;
        var info = e.currentTarget.dataset.info;
        swan.setStorageSync('prodetail', info);
        swan.navigateTo({
            url: '../productDetail/productDetail'
        });
    },
    onShow() {
        let id = swan.getStorageSync('iiid') ? swan.getStorageSync('iiid') : 0;
        this.setData({
            currentIndex: id
        })
    },
    // 选择分类
    choose(e) {
        let index = e.currentTarget.dataset.index;
        this.setData({
            currentIndex: index
        });
    },
    onLoad: function (e) {
        let pros;
        let arr = this.data.array;
        let index = this.data.index;
        let area = arr[index];
        for (let i = 0; i < getApp().globalData.config.length; i++) {
            if (getApp().globalData.config[i].key == 'pros') {
                pros = getApp().globalData.config[i];
                break;
            }
        }
        this.setData({
            imageurl: getApp().globalData.imageurl
        })
        let cates = pros.childrens;  //
        let show = this.data.show;
        for (let i = 0; i < cates.length; i++) {
            getApp().rq('/Index/getList', {
                typeid: cates[i].id,
                limit: 8,
                sort: pros.sortname,
                area
            }).then(res => {
                cates[i].data = res.data;
                if (cates[i].data.length == '0') {
                    cates[i].show = false;
                } else {
                    cates[i].show = true;
                }
                // show[i] = cates[i].data.length == '0'?true:false
                this.setData({
                    cates: cates,
                })
            });
        }
    },
});